<?php

namespace App\Http\Controllers\Guest;

use App\Http\Controllers\Controller;
use App\Model\Contato;
use Illuminate\Http\Request;

class ContatosController extends Controller
{
    public function Index()
    {
        return view('contatos');
    }

    public function store(Request $rq)
    {
        $this->validate($rq, [
            'email' => ['required', 'email'],
            'name' => ['required'],
            'body' => ['required', 'unique:contatos']
        ]);
        $contato = new Contato();
        $contato->name = $rq->name;
        $contato->email = $rq->email;
        $contato->body = $rq->body;
        $out = $contato->saveOrFail();
        return view('contatos')->with('out', $out);
    }
}
